<template >
  <body>
  <div class="root1">

    <div class="content">
        <div class="head1">
          <img src="../assets/x.svg" @click="toMedicineList"/>
          <h2 class="mdc-tital" style="font-size: 16px;" >中药详情</h2>
          <div style="width: 65px;height: 52px;"></div>
        </div>
        
        <div class="mdc-name1">
          <div class="name">{{ medicineDetails.medicine_name }}</div><img :src="medicineDetails.image_url"/>
        </div>
        <hr>
        <div class="tropism">
          <div>性味归经</div><div>{{ medicineDetails.tropism }}</div>
        </div>
        <hr>
        <div class="functions">
          <div class="functions-name">功能主治</div><div>{{ medicineDetails.functions }}</div>
        </div>
        <hr>
        <div class="description">
          <div class="description-name">简介</div><div>{{ medicineDetails.description }}</div>
        </div>
        <hr>
        <div style="height: 500px;"></div>
    </div>


  </div>  
</body> 
</template>

<script setup lang="ts">
import { onMounted,ref } from 'vue';
import { useRoute } from 'vue-router';
import router from '../router';
onMounted(async () => {
    const response = await fetch(`/api/medicine_detail?${medicineId}`)    
    const data = await response.json()
    console.log(data);
    medicineDetails.value = data["data"]
    console.log(medicineDetails.value);
    
    //medicineList.value = data["data"]["list"]
})

interface medicineDetail {
  id: number;
  medicine_name: string;
  image_url: string;
  description: string;
  tropism:string;//性味归经
  functions:string;//功能主治
  
}
let medicineDetails = ref<medicineDetail>({
  id: 0,
  medicine_name: '  ',
  image_url: 'https://via.placeholder.com/400x400/125b95/c0dda0.gif',
  description: '黄芪具有补气升阳的功效，常用于脾气虚、气虚乏力、易感冒等症状。',
  tropism: '归脾、肺经',
  functions: ''
})



//获取传来的id

const route = useRoute();
const medicineId = route.params.id;

console.log(medicineId);
const toMedicineList = () => {
    router.push('/medicineList');
};

</script>

<style lang="css" scoped>
body{
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh; /* 确保 body 元素至少占据浏览器窗口的高度，方便居中效果呈现 */
}
img{
  width: 52px;
  height: 52px;
  border-radius: 100%;
}
.root1{max-width: 550px;
    margin: 0 auto;
    background-color: #fff;
    position: fixed;
    top: 0%;
    width: 100%;
}
.head1{
    display: flex;
    justify-content: center;
    height: 50px;
    width: 100%;
    align-items: center;
    
    background-color: #fff;
    position: fixed;
    max-width: 520px;
    top: 0;
    display: flex;
    justify-content: space-between;
}
.mdc-title {
    align-self: center;
    font-size: 16px;

}


.mdc-name1{
  margin: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #1D2129;
  margin-top: 62px;
}
.tropism{
  margin: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 50px;
  color: #1D2129;
}
.functions{
  margin: 6px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-start;
  color: #1D2129;
}
.functions-name{
  margin-top: 6px;
  margin-bottom: 12px;
}
.description{
  margin: 6px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-start;
  color: #1D2129;
  margin-bottom: 12px;
}
.description-name{
  margin-top: 6px;
  margin-bottom: 12px;
}
hr{
  height: 0.1px;
  border-color: #ededed;
  color: #fcfcfc;
  opacity: 0.2;
}

</style>